package org.smart4j.plugin.security.tag;

import java.util.Arrays;

import org.apache.shiro.subject.Subject;
import org.apache.shiro.web.tags.RoleTag;

/**
 * description: 判断当前用户是否包含全部角色 （逗号分隔，表示"与"的关系）
 * @version v1.0
 * @author w
 * @date 2018年11月18日下午9:30:25
 **/
public class HasAllRolesTag extends RoleTag {

	private static final long serialVersionUID = 1L;
	
	private static final String ROLE_NAMES_DELIMITER = ",";
	
	@Override
	protected boolean showTagBody(String roleName) {
		boolean hasAllRoles = false ;
		Subject subject = getSubject();
		if(null != subject){
			if(subject.hasAllRoles(Arrays.asList(roleName.split(ROLE_NAMES_DELIMITER)))){
				hasAllRoles = true ; 
			}
		}
		return hasAllRoles;
	}

}
